package com.home.action;

import com.home.common.BaseAction;
import com.home.entity.User;
import com.home.entity.UserInfo;
import com.home.service.UserService;
import com.home.timesheet.entity.TimesheetVOImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserAction extends BaseAction {
    private UserService userService;
    private User user;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    /**
     * 用户登陆
     * 
     * @return
     */
    public String login() {
        User userLogin = userService.findUserByUser(user);
        if (userLogin != null) {
            super.getSession().put("USER", userLogin);
            return "loginSuccess";
        }
        return "error";
    }

    /**
     * 添加用户
     * 
     * @return
     */
    public String add() {
        UserInfo info = new UserInfo();
        info.setUser(user);
        user.setUserinfo(info);
        int flag = userService.addUser(user);
        if (flag == 0) {
            return "addError";
        }
        return "addSuccess";
    }

}
